package cn.virens.database.serviceimpl.platform.common;

import cn.hutool.core.util.StrUtil;

public class TableFileUtil {
	public static String controlPath(TableInfo info) {
		return toPath(info.getBasePackage(), info.getControlPackage(), info.getTablePackage());
	}

	public static String controlName(TableInfo info) {
		return info.getTableName() + "Contorller.java";
	}

	public static String controlFile(String root, TableInfo info) {
		return root + "/" + controlPath(info) + "/" + controlName(info);
	}

	public static String servicePath(TableInfo info) {
		return toPath(info.getBasePackage(), info.getServicePackage(), info.getTablePackage());
	}

	public static String serviceName(TableInfo info) {
		return info.getTableName() + "Service.java";
	}

	public static String serviceFile(String root, TableInfo info) {
		return root + "/" + servicePath(info) + "/" + serviceName(info);
	}

	public static String serviceImplPath(TableInfo info) {
		return toPath(info.getBasePackage(), info.getServiceImplPackage(), info.getTablePackage());
	}

	public static String serviceImplName(TableInfo info) {
		return info.getTableName() + "ServiceImpl.java";
	}

	public static String serviceImplFile(String root, TableInfo info) {
		return root + "/" + serviceImplPath(info) + "/" + serviceImplName(info);
	}

	private static String toPath(String _package0, String _package1, String _package2) {
		return toPath(_package0 + "." + _package1 + "." + _package2);
	}

	public static String pageFile(String root, TableInfo info, String name) {
		return root + "/html/" + info.getPath() + "/" + info.getKey() + "/" + name + ".html";
	}

	private static String toPath(String _package) {
		return StrUtil.replace(_package, ".", "/");
	}
}
